package com.ruoyi.tsjData.service.impl;

import java.util.List;
import java.util.concurrent.Future;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.calculate.BezierCurveUtil;
import com.ruoyi.tsjData.domain.pad.TshjZhdlOneDataDto;
import com.ruoyi.tsjData.domain.plat.DataTshjZhd;
import com.ruoyi.tsjData.domain.plat.DataTshjZhdl;
import com.ruoyi.tsjData.mapper.DataTshjZhdlMapper;
import com.ruoyi.tsjData.service.IDataTshjZhdlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;


/**
 * 提升机-制动力测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@Service
public class DataTshjZhdlServiceImpl implements IDataTshjZhdlService
{
    @Autowired(required = false)
    private DataTshjZhdlMapper dataTshjZhdlMapper;

    /**
     * 查询提升机-制动力测试
     * 
     * @param zhdlId 提升机-制动力测试主键
     * @return 提升机-制动力测试
     */
    @Override
    public DataTshjZhdl selectDataTshjZhdlByZhdlId(Long zhdlId)
    {
        return dataTshjZhdlMapper.selectDataTshjZhdlByZhdlId(zhdlId);
    }

    /**
     * 制动力测试数据
     * @param dataTaskId
     * @return
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataTshjZhdl>> selectZhdl(Long dataTaskId) {
        List<DataTshjZhdl> dataTshjZhdlEntities = dataTshjZhdlMapper.selectDataTshjZhdlByDataTaskId(dataTaskId);
        if (dataTshjZhdlEntities.size() != 0) {
            dataTshjZhdlEntities.forEach(item -> {
                if (item.getZhdlList() != null && item.getZhdlList().length() != 0) {
                    item.setTshjZhdlOneDataDtoList(JSON.parseArray(item.getZhdlList(), TshjZhdlOneDataDto.class));
                    for(TshjZhdlOneDataDto tshjZhdlOneDataDto : item.getTshjZhdlOneDataDtoList()) {
                        if(StringUtils.equals("0", tshjZhdlOneDataDto.getPull())) {
                            tshjZhdlOneDataDto.setPull("压");
                        }else {
                            tshjZhdlOneDataDto.setPull("拉");
                        }
                    }
                }
            });
        }
        return new AsyncResult<>(dataTshjZhdlEntities);
    }


    /**
     * 查询提升机-制动力测试
     *
     * @param dataTaskId 提升机-制动力测试任务id
     * @return 提升机-制动力测试
     */
    @Override
    public List<DataTshjZhdl> selectDataTshjZhdlByDataTaskId(Long dataTaskId) {
        return dataTshjZhdlMapper.selectDataTshjZhdlByDataTaskId(dataTaskId);
    }

    /**
     * 查询提升机-制动力测试列表
     * 
     * @param dataTshjZhdl 提升机-制动力测试
     * @return 提升机-制动力测试
     */
    @Override
    public List<DataTshjZhdl> selectDataTshjZhdlList(DataTshjZhdl dataTshjZhdl)
    {
        return dataTshjZhdlMapper.selectDataTshjZhdlList(dataTshjZhdl);
    }

    /**
     * 新增提升机-制动力测试
     * 
     * @param dataTshjZhdl 提升机-制动力测试
     * @return 结果
     */
    @Override
    public int insertDataTshjZhdl(DataTshjZhdl dataTshjZhdl)
    {
        dataTshjZhdl.setCreateTime(DateUtils.getNowDate());
        return dataTshjZhdlMapper.insertDataTshjZhdl(dataTshjZhdl);
    }


    /**
     * 批量新增制动力数据
     * @param dataTshjZhdls 提升机-制动力测试
     * @return
     */
    @Override
    public int batchDataTshjZhdl(List<DataTshjZhdl> dataTshjZhdls) {
        return dataTshjZhdlMapper.batchDataTshjZhdl(dataTshjZhdls);
    }

    /**
     * 修改提升机-制动力测试
     * 
     * @param dataTshjZhdl 提升机-制动力测试
     * @return 结果
     */
    @Override
    public int updateDataTshjZhdl(DataTshjZhdl dataTshjZhdl)
    {
        dataTshjZhdl.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataTshjZhdl.getTshjZhdlOneDataDtoList().isEmpty()) {
            dataTshjZhdl.setZhdlList(JSON.toJSONString(dataTshjZhdl.getTshjZhdlOneDataDtoList()));
        }
        return dataTshjZhdlMapper.updateDataTshjZhdl(dataTshjZhdl);
    }

    /**
     * 批量修改提升机-制动力测试
     * @param dataTshjZhdls 提升机-制动力测试
     * @return
     */
    @Override
    public int updateBatchDataTshjZhdl(List<DataTshjZhdl> dataTshjZhdls) {
        return dataTshjZhdlMapper.updateBatchDataTshjZhdl(dataTshjZhdls);
    }

    /**
     * 变更制动力测试任务状态
     * @param dataTaskIds 提升机-制动力测试任务ids
     * @return
     */
    @Override
    public int updateDataTshjZhdlByDataTaskIds(Long[] dataTaskIds) {
        return dataTshjZhdlMapper.updateDataTshjZhdlByDataTaskIds(dataTaskIds);
    }

    /**
     * 变更制动力测试任务状态为2
     * @param dataTaskId
     * @param zhdlId
     * @return
     */
    @Override
    public int updateDataTshjZhdlByZhlId(Long dataTaskId, Long zhdlId) {
        return dataTshjZhdlMapper.updateDataTshjZhdlByZhlId(dataTaskId, zhdlId);
    }

    /**
     * 批量删除提升机-制动力测试
     * 
     * @param zhdlIds 需要删除的提升机-制动力测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjZhdlByZhdlIds(Long[] zhdlIds)
    {
        return dataTshjZhdlMapper.deleteDataTshjZhdlByZhdlIds(zhdlIds);
    }

    /**
     * 删除提升机-制动力测试信息
     * 
     * @param zhdlId 提升机-制动力测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjZhdlByZhdlId(Long zhdlId)
    {
        return dataTshjZhdlMapper.deleteDataTshjZhdlByZhdlId(zhdlId);
    }
}
